home *** CD-ROM | disk | FTP | other *** search
/ Acorn Risc Technologies StrongARM CD-ROM / Acorn Risc Technologies StrongARM CD-ROM.iso / ftp / documents / appnotes / 046_060 / 051c / Text
Encoding:
Text File  |  1993-08-02  |  6.3 KB  |  228 lines

  1. 7th August 1992
  2. -----------------------------------------------------------------------------
  3. Support Group Application Note 
  4. Number: 051
  5. Issue: 1 
  6. Author:
  7. -----------------------------------------------------------------------------
  8.  
  9. Master 512: Mouse Driver Demo Program
  10.  
  11. -----------------------------------------------------------------------------
  12. Applicable Hardware: BBC Master 512
  13.  
  14. Related Application Notes:
  15.  
  16.  
  17. -----------------------------------------------------------------------------
  18. Copyright (C) Acorn Computers Limited 1992
  19.  
  20. Every effort has been made to ensure that the information in this leaflet is 
  21. true and correct at the time of printing. However, the products described in
  22. this leaflet are subject to continuous development and improvements and
  23. Acorn Computers Limited reserves the right to change its specifications at
  24. any time. Acorn Computers Limited cannot accept liability for any loss or
  25. damage arising from the use of any information or particulars in this
  26. leaflet. ACORN, ECONET and ARCHIMEDES are trademarks of Acorn Computers
  27. Limited.
  28. -----------------------------------------------------------------------------
  29. Support Group
  30. Acorn Computers Limited
  31. Acorn House
  32. Vision Park
  33. Histon
  34. Cambridge       CB4 4AE
  35. -----------------------------------------------------------------------------
  36.  
  37.  
  38. This program demonstrates how to interface to the Acorn Master 512 mouse.
  39.  
  40.  
  41. ;This program claims the mouse, setting up an interrupt routine to note the
  42. mouse information as it comes ;in.  The main program prints out the current
  43. state of the mouse continually until both mouse buttons are ;depressed.  We
  44. then release the mouse and exit gracefully.
  45.  
  46. ;  To produce a .EXE file use DRI tools
  47. ;
  48. ;  RASM86.EXE MOUSE
  49. ;  LINK86.EXE MOUSE
  50. ;
  51.  
  52. Cr                      equ     13
  53. Lf                      equ     10
  54.  
  55. Bdos                    equ     21h
  56.  
  57. Print_string                    equ     9
  58. Exit                    equ     4c00h
  59.  
  60. Mouse_button_exit               equ     5       ; both buttons down
  61.  
  62. OEM_Mouse                       equ     134
  63. Claim_Mouse                     equ     0
  64. Release_Mouse           equ     1
  65.  
  66. XIOS_ENTRY              equ     dword ptr .0028h
  67. dos_plus_RLR            equ     word ptr .4eh
  68.  
  69. cseg
  70.         mov     dx, offset msg_header
  71.         mov     ah, Print_string
  72.         int     Bdos                    ; say hello
  73.  
  74.         call    init_xios_calls                 ;initialise the XIOS routine
  75.         call    install_mouse                   ;install mouse interrupt
  76.                                                 ;handler  
  77. print_loop:
  78.         call    display_info                    ;display state of the mouse
  79.         cmp     cs: mouse_buttons, Mouse_button_exit
  80.         jne     print_loop                      ; should we exit?
  81.  
  82.         call    remove_mouse            ; remove mouse interrupt handler
  83.         mov     ax, Exit                        ; and exit the program
  84.         int     Bdos
  85.  
  86. ;
  87. ;  This interrupt routine is called by Dos Plus with the current state of
  88. ;the mouse.  Save this information and  
  89. ;  return with a RETF, all registers should be preserved.
  90.  
  91. i_mouse:
  92. ;-----------
  93. ; On entry      AX = mouse buttons
  94. ;       CX = mouse X coordinates
  95. ;       DX = mouse Y coordinates
  96. ;
  97. ; Note that you cannot make DOS system calls from within an interrupt
  98. ;safely, so the information is simply stored for display later
  99.         mov     cs: mouse_buttons, ax
  100.         mov     cs: mouse_x_loc, cx
  101.         mov     cs: mouse_y_loc, dx
  102.         retf
  103.  
  104. mouse_buttons   dw      0
  105. mouse_x_loc             dw      0
  106. mouse_y_loc             dw      0
  107.  
  108.  
  109. display info:
  110. ;--------------
  111. ;
  112. ; Print mouse status in the form
  113. ; "X = nnnn Y = nnnn Buttons = nnnn"
  114. ;
  115.         mov     dx, offset msg_x_coord
  116.         mov     ah, Print_string
  117.         int     Bdos
  118.         mov     ax, cs: mouse_x_loc
  119.         call    display_word
  120.  
  121.         mov     dx, offset msg_y-coord
  122.         mov     ah, Print_string
  123.         int     Bdos
  124.         mov     ax, cs: mouse_y_loc
  125.         call    display_word
  126.  
  127.         mov     dx, offset msg_buttons
  128.         mov     ah, Print_string
  129.         int     Bdos
  130.         mov     ax, cs: mouse_buttons
  131.         call    display_word
  132.  
  133.         mov     dx, offset msg_return
  134.         mov     ah, Print_string
  135.         int     Bdos
  136.         ret
  137.  
  138.  
  139. display_word:
  140. ;----------------
  141. ;
  142. ; Display the contents of AX in as a Hex word of the form "nnnn"
  143. ;
  144.         push    ax
  145.         mov     al, ah
  146.         call    display_byte
  147.         pop     ax
  148. display_byte:
  149.         push    ax
  150.         mov     cl, 4
  151.         shr     al, cl
  152.         call    display_nibble
  153.         pop     ax
  154. display_nibble:
  155.         and     al, 0fh
  156.         mov     bx, offset bin_to_ascii
  157.         xlat    al
  158.         mov     dl, al
  159.         mov     ah, 2
  160.         int     21h
  161.         ret
  162.  
  163.  
  164. ini5_xios_calls:
  165. ;------------------
  166.         int     0feh                    ; get @sysdat address
  167.         mov     sysdat, ax                      ; and save for later
  168.         ret
  169.  
  170.  
  171. xios:
  172. ;-----
  173.         push    ds                      ; we must first
  174.         mov     ds, sysdat                      ; point DS at the SYStem DATa
  175.         push    es                        area
  176.         mov     es, DOS_PLUS_rlr                ; point ES at User Data Area
  177.                                         ; which is in Ready List Root
  178.         callf   XIOS_ENTRY              ; and we can then call the XIOS
  179.         pop     es
  180.         pop     ds
  181.         ret
  182.  
  183.  
  184. install_mouse:
  185. ;-----------------
  186.         pushf                   ; turn off interrupts
  187.         cli
  188.  
  189.         mov     ax, OEM_Mouse
  190.         mov     cl, Clain_Mouse ; take over the mouse
  191.         mov     bx, cs          ; BX:DX = address of our interrupt routine
  192.         mov     dx, offset i_mouse
  193.         call    xios
  194.  
  195.         popf                    ; interrupts OK now
  196.         ret
  197.  
  198.  
  199. remove_mouse:
  200. ;------------------
  201.         pushf                   ; no interrupts
  202.         cli
  203.         mov     ax, OEM_Mouse
  204.         mov     cx, Release_Mouse       ; release mouse
  205.         call    xios
  206.         popf
  207.         ret
  208.  
  209.  
  210. dseg
  211.  
  212. msg_header              db      'Mouse Demo Program', cr, lf, '$'
  213. msg_x_coord             db      '  X = $ '
  214. msg_y_coord             db      '  Y = $ '
  215. msg_buttons             db      '  Buttons = $ '
  216. msg_return              db      Cr, '$'
  217.  
  218. bin_to_ascii            db      '0123456789ABCDEF'
  219.  
  220. sysdat          dw      0
  221.  
  222. sseg
  223.  
  224.                 rw      200     ; some stack for the program
  225.  
  226. end
  227.         
  228.